package comparator;

import java.util.Date;
import java.util.Comparator;

import dataBase.Order;

public class SortByEndDate {

	private static class Holder{
		static SortByEndDate inst =new SortByEndDate();
	}

	private static Comparator<Order> com;
	
	private SortByEndDate() {
	com = new Comparator<Order>() {
		@Override
		public int compare(Order o1, Order o2) {
			Date firstDate = o1.getEndTime();
			Date secondDate = o2.getEndTime();
			int returnVal;
			if (firstDate.before(secondDate))
				returnVal=1;
			else if (firstDate.after(secondDate))
				returnVal=-1;
			else returnVal=0;
			return returnVal;
		}
		};//end of comparator
	}
	
	public static SortByEndDate getInstance()  {
	   	//return the singelton
		return Holder.inst;
	   }
	
	public Comparator<Order> getDateComparator(){
		return com;
	}
}
